// 格式化时间
export const showCurrentTime = (time) => {
  let date = typeof time === "number" ? new Date(time) : new Date((time || "").replace(/-/g, "/"));
  let diff = (new Date().getTime() - date.getTime()) / 1000;
  let dayDiff = Math.floor(diff / 86400);

  let isValidDate = Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date.getTime());

  if (!isValidDate) {
    window.console.error("不是有效日期格式");
  }
  const formatDate = function (date) {
    let today = new Date(date);
    let year = today.getFullYear();
    let month = ("0" + (today.getMonth() + 1)).slice(-2);
    let day = ("0" + today.getDate()).slice(-2);
    let hour = today.getHours();
    let minute = today.getMinutes();
    let second = today.getSeconds();
    return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  };
  //小于0或者大于等于31显示原时间
  if (isNaN(dayDiff) || dayDiff < 0 || dayDiff >= 2) {
    return formatDate(date);
  }
  return (
    (dayDiff === 0 &&
      ((diff < 60 && "刚刚") ||
        (diff < 120 && "1分钟前") ||
        (diff < 3600 && Math.floor(diff / 60) + "分钟前") ||
        (diff < 7200 && "1小时前") ||
        (diff < 86400 && Math.floor(diff / 3600) + "小时前"))) ||
    (dayDiff === 1 && "昨天") ||
    (dayDiff < 7 && dayDiff + "天前") ||
    (dayDiff < 31 && Math.ceil(dayDiff / 7) + "周前")
  );
};

// 格式 时间格式
export const setTime = (val) => {
  // console.log(val)
  let year = val.getFullYear(); //年
  let month = val.getMonth() + 1; //月
  let day = val.getDate(); //日
  let hour = val.getHours(); //时
  let minute = val.getMinutes(); //分
  if (month >= 1 && month <= 9) {
    month = `0${month}`;
  }
  if (day >= 1 && day <= 9) {
    day = `0${day}`;
  }
  if (hour >= 0 && hour <= 9) {
    hour = `0${hour}`;
  }
  if (minute >= 0 && minute <= 9) {
    minute = `0${minute}`;
  }
  return `${year}-${month}-${day}`;
};

// 固定发送人员信息不可删除
export const userLockList = [
  {
    userName: "邢志刚",
    img: "https://static-legacy.dingtalk.com/media/lADPBG1Q611Td-HNAzDNAmQ_612_816.jpg",
    userId: "03305558773917",
    isLock: true,
  },
  {
    userName: "陶师亮",
    img: "https://static-legacy.dingtalk.com/media/lADPBFRydOM2Eh7NAlTNAlQ_596_596.jpg",
    userId: "120163595537782172",
    isLock: true,
  },
  {
    userName: "韩晓兰",
    img: "https://static-legacy.dingtalk.com/media/lADPBG1Q5KlyowjNEYDNEYA_4480_4480.jpg",
    userId: "16068715551905448",
    isLock: true,
  },
  {
    userName: "陈沐英",
    img: "https://static-legacy.dingtalk.com/media/lQDPD4C8iDk7iS_NA6XNAl2wv4xsXB4SlYQFZGRiU4qHAA_605_933.jpg",
    userId: "17019977880593281",
    isLock: true,
  },
  //{
  //  userName: "赖静欣",
  //  img: "https://static-legacy.dingtalk.com/media/lADPBGnDbKZLos_NAo3NAlI_594_653.jpg",
  //  userId: "15978874344727997",
  //  isLock: true,
  //},

  // 测试
  //{
  //  userName: "方旺",
  //  img: "https://static-legacy.dingtalk.com/media/lADPDiQ3Ur7ZBl7NBA_NAwU_773_1039.jpg",
  //  userId: "16581062817924604",
  //  isLock: true,
  //},
];

// 随机字符串
export const getRandomString = (len) => {
  let _charStr = "abacdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789",
    min = 0,
    max = _charStr.length - 1,
    _str = ""; //定义随机字符串 变量
  //判断是否指定长度，否则默认长度为15
  len = len || 15;
  //循环生成字符串
  for (var i = 0, index; i < len; i++) {
    index = (function (randomIndexFunc, i) {
      return randomIndexFunc(min, max, i, randomIndexFunc);
    })(function (min, max, i, _self) {
      let indexTemp = Math.floor(Math.random() * (max - min + 1) + min),
        numStart = _charStr.length - 10;
      if (i == 0 && indexTemp >= numStart) {
        indexTemp = _self(min, max, i, _self);
      }
      return indexTemp;
    }, i);
    _str += _charStr[index];
  }
  return _str;
};
